# -*- coding: utf-8 -*-
from datetime import datetime
from abc import ABC
from app.views import CommonHandler
from app.models.dao import db2meta, update
import app.models.model as model
import app.tools.SafeMonitorTools.m_position_layer_type as smType
meta_id = smType.default_MetaId
TypeModelDict = {
    'line': model.LineModel,
    'lwpolyline':model.LWPolylineModel,
    'hatch':model.HatchModel,
    'arc': model.ArcModel,
    'circle': model.CircleModel,
    'ellipse': model.EllipseModel
}
class Layer_Feature_Handler(CommonHandler, ABC):
    async def put(self):
        params = self.json_params()
        id,type,layerName = params.values()
        mateModel = TypeModelDict[type]
        update(mateModel,id,{'layer':layerName})
        # 每次图层更新完成以后，都要将meta版本 + 1
        meta = db2meta(meta_id)
        metaid = meta['id']
        version_num = meta['mine_name'][1:]
        newVersion = 'v' + str(int(version_num) + 1)
        meta['mine_name'] = newVersion
        # 时间也需要做更新
        meta['update_time'] = datetime.now()
        meta['create_time'] = datetime.fromisoformat(meta['create_time'])
        update(model.MetaModel,metaid,meta)
        await self.respose(data={'status':200})






